﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm
{
    /// <summary>
    /// 字符串
    /// </summary>
    public class StringAlgorithm
    {
        /// <summary>
        /// 344. 反转字符串
        /// </summary>
        /// <param name="s"></param>
        public void ReverseString(char[] s)
        {
            int length = s.Length / 2;
            for (int i = 0; i < length; i++)
            {
                char temp = s[i];
                s[i] = s[s.Length-1 - i];
                s[s.Length-1 - i]= temp;
            }
        }
        /// <summary>
        /// 7. 整数反转
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        public int Reverse(int x)
        {
            long n = 0;
            while (x!=0)
            {
                n = n*10+x%10;
                x /= 10;
            }
            return (n > 2147483647 || n <-2147483648) ? 0 : Convert.ToInt32(n);
        }
    }
}
